import matplotlib.pyplot as plt

# plt.style.use(['science','no-latex'])
# plt.style.use(['science'])
# plt.style.use(['science','ieee', 'no-latex'])
# plt.style.use(['science','nature'])
# plt.style.use(['science','bright', 'no-latex'])
# plt.style.use(['science','vibrant', 'no-latex'])
# plt.style.use(['science','muted', 'no-latex'])
# plt.style.use(['science','high-contrast','grid'])
# plt.style.use(['science','ieee','light','grid'])
plt.rc('font', family='Times New Roman') 


import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
Z = np.array([[90.108,89.245,88.374,88.111,89.383],
[87.208,87.097,88.474,88.799,87.891],
[88.715,89.618,88.357,88.808,87.619],
[90.588,88.880,87.787,87.340,89.461],
[89.465,88.039,87.400,87.948,88.116]])



def draw_3d_pic(name,Z):
    X = np.array([0.1,0.3,0.5,0.7,0.9])
    Y = np.array([0.1,0.3,0.5,0.7,0.9])
    X, Y = np.meshgrid(X, Y)
    fig, ax = plt.subplots(subplot_kw={"projection": "3d"},figsize=(10,15))
    # fig.patch.set_alpha(1)
    norm = matplotlib.colors.Normalize(vmax = 92, clip = False)
    norm = matplotlib.colors.Normalize(clip = False)
    # ax.set_xlabel(r'$\alpha$',size=17)   # here
    # ax.set_ylabel(r'$\beta$',size=17)
    # ax.set_zlabel(name,size=18)
    fig.text(0.79, 0.31, r'$\beta$', size=18)
    fig.text(0.35, 0.26, r'$\alpha$', size=18)
    fig.text(0.883, 0.535, name, size=18)

    ax.set_xticks([0.1,0.3,0.5,0.7,0.9])
    ax.set_yticks([0.1,0.3,0.5,0.7,0.9])
    # ax.set_zticks([78, 82, 86, 90])
    jiange = (np.max(Z)//1 - np.min(Z)//1) // 4 if (np.max(Z)//1 - np.min(Z)//1)%4 == 0 else (np.max(Z)//1 - np.min(Z)//1) // 4 + 1
    ax.set_zticks([np.min(Z)//1-1, np.min(Z)//1+jiange-1, np.min(Z)//1+jiange*2-1, np.min(Z)//1+jiange*3-1, np.min(Z)//1+jiange*4-1, np.min(Z)//1+jiange*5-1])
    ax.invert_xaxis()


    ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
    ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
    ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
    
    ax.tick_params(labelsize=17)
    ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([1, 1, 1, 1]))
    ax.view_init(20, -45)
    
    ax.plot_surface(X, Y, Z, cmap="cool",norm=norm, edgecolors='k', lw=0.8)
    # ax.set_zlim(80,95)
    # ax.set_zlim(78,90)
    ax.set_zlim(np.min(Z)//1-1,np.min(Z)//1+jiange*5-1)
    ax.patch.set_facecolor('white')
    
    plt.savefig("/home/hlf/code/draw_image/HHGSI//{}.png".format(name), dpi=300,format="png")
# plt.show()


Z = np.array([[90.108,89.245,88.374,88.111,89.383],
[87.208,87.097,88.474,88.799,87.891],
[88.715,89.618,88.357,88.808,87.619],
[90.588,88.880,87.787,87.340,89.461],
[89.465,88.039,87.400,87.948,88.116]])
draw_3d_pic('Micro-P',Z)
# Z = np.array([
# [86.1,86.338,86.338,85.941,86.259],
# [86.100 ,85.782,86.577,86.894,87.053],
# [85.544,85.703,84.988,86.974,85.862],
# [85.624,86.974,87.927,86.577,85.624],
# [87.689,85.941,86.497,85.782,86.577]
# ])
# draw_3d_pic('Micro-R',Z)
# Z = np.array([
# [88.058,87.767,87.344,87.012,87.793],
# [86.651,86.435,87.515,87.836,87.470],
# [87.101,87.617,86.640 ,87.881,86.239],
# [88.036,87.916,87.857,86.957,87.5],
# [88.568,86.977,86.946,86.852,87.340], 
# ])
# draw_3d_pic('Micro-F1',Z)
# Z = np.array([
# [85.766,84.507,84.318,82.584,81.778],
# [82.613,84.043,84.488,84.613,82.079],
# [83.210 ,85.270 ,80.633,83.468,81.466],
# [87.170 ,86.258,83.255,81.955,83.964],
# [84.870 ,81.922,83.492,82.997,82.264],

# ])
# draw_3d_pic('Macro-P',Z)
# Z = np.array([
# [81.948,81.246,80.191,80.289,78.229],
# [78.586,79.731,84.404,80.979,81.584],
# [77.343,78.406,76.320 ,81.183,80.780],
# [79.983,79.145,81.227,79.836,78.827],
# [79.371,77.955,79.955,78.356,78.483],

# ])
# draw_3d_pic('Macro-R',Z)
# Z = np.array([
# [83.762,82.483,81.766,81.177,79.767],
# [79.919,81.340 ,84.292,82.596,81.568],
# [79.891,81.170 ,78.330 ,81.994,80.841],
# [83.157,81.867,82.078,80.809,81.138],
# [81.516,79.252,81.387,80.471,80.147],

# ])
# draw_3d_pic('Macro-F1',Z)
# Z = np.array([
# [84.258,83.591,83.215,82.864,83.340],
# [82.255,82.566,83.272,83.877,83.383],
# [82.284,84.129,83.063,83.807,81.646],
# [84.205,84.081,84.220 ,82.407,83.281],
# [84.702,82.514,83.030 ,82.197,83.302],

# ])
# draw_3d_pic('mAP',Z)